'''
封装requests中的get、post方法
1.增加异常处理
2.创建一个session，用session发送请求，保持状态
3.打印日志，方便定位问题
'''
import pytest
import requests


class BaseRequests:
    # 构造方法
    def __init__(self):
        self.session = requests.Session()


    def get(self, url, **kwargs):
        try:
            print(f"发送get请求,url为：{url},参数为：{kwargs}")
            r = self.session.get(url, **kwargs)
            print(f"发送get请求成功，响应为：{r.text}")
            return r
        except Exception as e:
            print(f"发送get请求异常，异常信息为：{e}")

    def post(self, url, **kwargs):
        try:
            print(f"发送post请求,url为：{url},参数为：{kwargs}")
            r = self.session.post(url, **kwargs)
            print(f"发送post请求成功，响应为：{r.text}")
            return r
        except Exception as e:
            print(f"发送post请求异常，异常信息为：{e}")


if __name__ == '__main__':
    br = BasrRequests()
    cs = {"mobilephone": "18012345678", "pwd": "123", "regname": "asdfasd"}
    url = "http://192.168.0.103:8088/futureloan/mvc/api/member/register"
    br.get(url, params=cs)
    br.post(url, params=cs)
